//
//  RMMYouHuiQuanTableViewCell.m
//  Romomo
//
//  Created by puman on 16/10/17.
//  Copyright © 2016年 mazegong. All rights reserved.
//

#import "RMMYouHuiQuanTableViewCell.h"

@implementation RMMYouHuiQuanTableViewCell
{
    UILabel *_name;
    UILabel *_moneyLabel;
    UILabel *_dateLabel;
    UILabel *_zeKouLabe;
    UIImageView *_backImageV;
    UIButton *_imageBut;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = RGBA(245, 246, 247, 1);
        _backImageV = [[UIImageView alloc] initWithFrame:CGRectMake(15, 16, kScreenWideth- 30, 120)];
        _backImageV.userInteractionEnabled= YES;
        [self.contentView addSubview:_backImageV];
        
        _name = [[UILabel alloc] initWithFrame:CGRectMake(22, 18, _backImageV.width - 22 - 32, kMaric)];
        _name.text = @"折扣券";
        _name.font = kFont(18);
        [_backImageV addSubview:_name];
        
        _selcetImageV = [[UIImageView alloc] initWithFrame:CGRectMake(_backImageV.width -32, 12, kMaric, kMaric)];
        _selcetImageV.hidden = YES;
        _selcetImageV.image = [UIImage imageNamed:@"优惠券可选@3x"];
        [_backImageV addSubview:_selcetImageV];
        
        _imageBut = [UIButton buttonWithType:(UIButtonTypeCustom)];
        _imageBut.frame = CGRectMake(0, _backImageV.height - 44, 22, 15);
        [_backImageV addSubview:_imageBut];
        
        _moneyLabel = [[UILabel alloc] initWithFrame:CGRectMake(_imageBut.right, _imageBut.top, _backImageV.width - _imageBut.right - 90, 15)];
        _moneyLabel.font = kFont(12);
        [_backImageV addSubview:_moneyLabel];
        
        _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(_moneyLabel.left, _moneyLabel.bottom, _moneyLabel.width, 15)];
        _dateLabel.font = kFont(12);
        [_backImageV addSubview:_dateLabel];
        
        _zeKouLabe = [[UILabel alloc] initWithFrame:CGRectMake(_backImageV.width - 90, _imageBut.top, 80, 36)];
        _zeKouLabe.font = kBFont(24);
        [_backImageV addSubview:_zeKouLabe];
        
    }
    return self;
}
- (void)setModel:(NSString *)model{
    if ([model isEqualToString:@"1"]) {
        _moneyLabel.textColor = kWhiteColor;
        _dateLabel.textColor = kWhiteColor;
        _zeKouLabe.textColor = kWhiteColor;
        _name.textColor = kWhiteColor;
        _backImageV.image = [UIImage imageNamed:@"优惠券可用@3x"];
        [_imageBut setImage:[UIImage imageNamed:@"提示2@3x"] forState:(UIControlStateNormal)];
        _selcetImageV.hidden = NO;

    } else {
        _moneyLabel.textColor = COLORFROMCODE(0x4A4A4A, 1);
        _dateLabel.textColor = COLORFROMCODE(0xBFBFBF, 1);
        _zeKouLabe.textColor = COLORFROMCODE(0xBFBFBF, 1);
        _name.textColor = COLORFROMCODE(0xBFBFBF, 1);
        _backImageV.image = [UIImage imageNamed:@"优惠券-不能用@3x"];
        _selcetImageV.hidden = YES;
        [_imageBut setImage:[UIImage imageNamed:@"提示1@2x"] forState:(UIControlStateNormal)];

    }
}
- (void)setDic:(NSDictionary *)dic{
    if (dic == nil) {
        return;
    }
    _moneyLabel.text = [NSString stringWithFormat:@"满%@元使用",[RMMFileManager retrunObjWith:dic[@"PRICE"]]];
    _dateLabel.text = [NSString stringWithFormat:@"有效期至: %@",[RMMFileManager retrunObjWith:dic[@"DATE_PERIOD"]]];
    _name.text = [RMMFileManager retrunObjWith:dic[@"VOUCHER_NAME"]];
    NSString *type = [NSString stringWithFormat:@"%@",dic[@"CARD_TYPE"]];
    NSString *discount = [RMMFileManager retrunObjWith:dic[@"DISCOUNT_RATE"]];
    NSString *price = [RMMFileManager retrunObjWith:dic[@"PAR_AMT"]];
    if ([type isEqualToString:@"7"]) {
        // 护理券
    } else if ([type isEqualToString:@"4"]) {
        // 折扣
        if (discount.length > 4) {
            _zeKouLabe.text = [NSString stringWithFormat:@"%.2f折",[discount floatValue] * 10];
        } else {
            _zeKouLabe.text = [NSString stringWithFormat:@"%.1f折",[discount floatValue] * 10];
        }
    } else if ([type isEqualToString:@"3"]) {
        // 推广卡
    } else if ([type isEqualToString:@"6"]) {
        // 代金券
        _zeKouLabe.text = [NSString stringWithFormat:@"%@元",price];
    } else if ([type isEqualToString:@"5"]) {
        // 产品券
    }
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:_zeKouLabe.text];
    [attributedString addAttribute:NSFontAttributeName value:kFont(16) range:NSMakeRange(_zeKouLabe.text.length - 1, 1)];
    [_zeKouLabe setAttributedText:attributedString];
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
